<template>
  <Modal
    width="800"
    v-model="visible"
    :title="title"
    :key="key"
    :loading="Loading"
  >
    <div style="width: 80%;padding-left: 10%;padding-right: 10%">
      <Spin size="large" fix v-if="Loading"></Spin>
      <Form :label-width="130" ref="formValidate" :model="formValidate"
            :rules="ruleValidate">
        <Form-item label="评分:" prop="score">
          <Rate v-model="formValidate.score"/>
        </Form-item>
        <Form-item label="评价:" prop="evaluation">
          <RadioGroup v-model="formValidate.evaluation">
            <Radio label="0" :disabled="true">未评价</Radio>
            <Radio label="1" :disabled="true">现场评价</Radio>
            <Radio label="2" :disabled="true">电话回访评价</Radio>
          </RadioGroup>
        </Form-item>
        <Form-item label="评价内容:" prop="content">
          <Input v-model="formValidate.content" type="textarea" :autosize="{minRows: 2,maxRows: 5}"
                 placeholder="请输入评价内容"/>
        </Form-item>
      </Form>
    </div>
    <div slot="footer">
      <Button @click="cancel">取消</Button>
      <Button type="primary" @click="ok">确定</Button>
    </div>
  </Modal>
</template>

<script>
  import axios from '@/libs/api.request'

  export function postAction(url, parameter) {
    return axios.request({
      url: url,
      method: 'post',
      data: parameter
    })
  }

  export default {
    data() {
      const validateScore = (rule, value, callback) => {
        if (!this.formValidate.score || this.formValidate.score === 0) {
          callback(new Error('请选择评分'))
        } else {
          callback()
        }
      }
      return {
        modal1: false,
        visible: false,
        title: '电话回访评价',
        model: {},
        formValidate: {
          score: 0
        },
        ruleValidate: {
          score: [
            { validator: validateScore, trigger: 'change' }
          ]
          // evaluation: [
          //   { required: true, message: '请选择评价', trigger: 'change' }
          // ]
        },
        key: '',
        url: '/api/ac/cscforxq/auditItemService/updateScore',
        Loading: false
      }
    },
    methods: {
      ok() {
        var that = this
        this.$refs['formValidate'].validate((valid) => {
          if (valid) {
            that.submitFrom()
          }
        })
      },
      submitFrom() {
        var that = this
        that.Loading = true
        postAction(that.url, that.formValidate).then((res) => {
          if (res.data.errcode !== 0) {
            this.$Notice.error(res.data.errmsg)
          } else {
            this.$Notice.success({ title: '评分完成', desc: res.data.errmsg })
            // that.$Notice.success('评分完成！')
            this.$emit('ok')
            this.visible = false
          }
        }).finally(() => {
          that.Loading = false
        })
      },
      cancel() {
        this.visible = false
      },
      add() {
        this.edit({})
      },
      edit(row) {
        this.formValidate.score = 0
        this.formValidate.evaluation = '2'
        this.formValidate.content = ''
        this.formValidate.code = row.code
        this.visible = true
      }
    }
  }
</script>
<style scoped>
</style>
